<?php include_once ('function/check_login_function.php'); onlyValid(); onlyAdmin();?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Health Tracker</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Health Tracker">
    <meta name="author" content="">

    <!-- Le styles -->
    <link href="css/bootstrap.css" rel="stylesheet">
    <style>
      body {
        padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
      }
    </style>
    <link href="css/bootstrap-responsive.css" rel="stylesheet">
    <link rel="shortcut icon" href="ico/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="ico/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="ico/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="ico/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="ico/apple-touch-icon-57-precomposed.png">
  </head>

  <body>

<?php include_once('nav.php'); ?>
    <div class="container">
    <div class="row">
    <div class="span4">
      <h1 style="padding-left: 20px;">Admin</h1>
				
				<h2 id="datalogtype">Manage Data Log Type List</h2>
				<?php $logtype_list = DataLog::getDataLogTypeList(); ?>
					<?php if ($logtype_list !== null) {?>
					<table>
					<tr>
					<th>ID</th>
					<th>Type</th>
					<th></th>
					</tr>
					<?php 
						
							foreach ($logtype_list as $logtype) {
								echo '<tr>';
								echo '<td>' . $logtype['datalog_type_id'] . '</td>';
								echo '<td>' . $logtype['datalog_type_name'] . '</td>';
								echo '<td>';
									echo '<form action="function/admin_function.php" method="POST">';
									echo '<input type="hidden" id="logTypeID" name="logTypeID" value="' . $logtype['datalog_type_id'] . '"/>';
									echo '<input type="hidden" id="from" name="from" value="admin.php#datalogtype"/>';
									echo '<input type="submit" name="deleteLogType" value="Delete" class="btn btn-primary"/> ';
									echo' </form>';
								echo '</td>';
								echo '</tr>';
							}
						}
					?>
					</table>
					<form action="function/admin_function.php" method="POST">
					<input type="text" id="typename" name="typename" /> 
					<input type="hidden" id="from" name="from" value="admin.php#datalogtype"/>
					<input type="submit" name="enterLogType" value="Add Type" /> <br /> 
					</form>
				
				<hr />
				
				<h2 id="notificationtype">Manage Notification Type List</h2>
				<p>
				Please do not delete request_doctor, request_patient, log_doctor, food_doctor and symptom_doctor because it is hardcoded. <br />
				If you want to edit these Notification types, some code modifications are required
				</p>
				<?php $notification_list = Notification::getNotificationTypeList(); ?>
					<?php if ($notification_list !== null) {?>
					<table>
					<tr>
					<th>ID</th>
					<th>Type</th>
					<th></th>
					</tr>
					<?php 
						
							foreach ($notification_list as $notification) {
								echo '<tr>';
								echo '<td>' . $notification['notification_type_id'] . '</td>';
								echo '<td>' . $notification['notification_type_name'] . '</td>';
								echo '<td>';
									echo '<form action="function/admin_function.php" method="POST">';
									echo '<input type="hidden" id="notificationTypeID" name="notificationTypeID" value="' . $notification['notification_type_id'] . '"/>';
									echo '<input type="hidden" id="from" name="from" value="admin.php#notificationtype"/>';
									echo '<input type="submit" name="deleteNotificationType" value="Delete" class="btn btn-primary"/> ';
									echo' </form>';
								echo '</td>';
								echo '</tr>';
							}
						}
					?>
					</table>
					<form action="function/admin_function.php" method="POST">
					<input type="text" id="typename" name="typename" /> 
					<input type="hidden" id="from" name="from" value="admin.php"/>
					<input type="submit" name="enterNotificationType" value="Add Notification Type" /> <br /> 
					</form>
				
				<hr />
				
				<h2 id="hospital">Manage Hospital List</h2>
				<?php $hospital_list = Hospital::getHospitalListWithCount(); ?>
					<?php if ($hospital_list !== null) {?>
					<table>
					<tr>
					<th>ID</th>
					<th>Name</th>
					<th>Address</th>
					<th>Contact</th>
					<th>No. of Doctor</th>
					<th></th>
					</tr>
					<?php 
						
							foreach ($hospital_list as $hospital) {
								echo '<tr>';
								echo '<td>' . $hospital['hospital_id'] . '</td>';
								echo '<td>' . $hospital['hospital_name'] . '</td>';
								echo '<td>' . $hospital['hospital_address'] . '</td>';
								echo '<td>' . $hospital['hospital_contact'] . '</td>';
								echo '<td>' . $hospital['doctor_count'] . '</td>';
								echo '<td>';
									echo '<form action="function/admin_function.php" method="POST">';
									echo '<input type="hidden" id="hospitalID" name="hospitalID" value="' . $hospital['hospital_id'] . '"/>';
									echo '<input type="hidden" id="from" name="from" value="admin.php#hospital"/>';

									if (intval($hospital['doctor_count']) === 0) {
										echo '<input type="submit" name="deleteHospital" value="Delete" class="btn btn-primary"/> ';
									} else {
										echo '<input type="submit" name="clearHospital" value="Clear Doctors" class="btn btn-primary"/> ';
									}
									
									echo' </form>';
								echo '</td>';
								echo '</tr>';
							}
						}
					?>
					</table>					
					
					<form action="function/admin_function.php" method="POST">
					<label for="name"> Name: </label> 
					<input type="text" id="name" name="name" /> <br />
					<label for="address"> Address: </label> 
					<input type="text" id="address" name="address" /> <br />
					<label for="contact"> Contact: </label> 
					<input type="text" id="contact" name="contact" /> <br />
					<input type="hidden" id="from" name="from" value="admin.php"/>
					<input type="submit" name="enterHospital" value="Add Hospital" /> <br /> 
					</form>			
					
					<hr />

				<h2 id="doctor">Manage Doctor List</h2>
				<?php $doctor_list = Doctor::getDoctorListWithCount(); ?>
					<?php if ($doctor_list !== null) {?>
					<table>
					<tr>
					<th>ID</th>
					<th>Name</th>
					<th>E-mail</th>
					<th>Contact</th>
					<th>Reg. no</th>
					<th>Speciality</th>
					<th>No. of Patient</th>
					<th></th>
					</tr>
					<?php 
						
							foreach ($doctor_list as $doctor) {
								echo '<tr>';
								echo '<td>' . $doctor['user_id'] . '</td>';
								echo '<td>' . $doctor['user_firstname'] . ' ' . $doctor['user_lastname'] . '</td>';
								echo '<td>' . $doctor['user_email'] . '</td>';
								echo '<td>' . $doctor['user_contact'] . '</td>';
								echo '<td>' . $doctor['doctor_regno'] . '</td>';
								echo '<td>' . $doctor['doctor_speciality'] . '</td>';
								echo '<td>' . $doctor['patient_count'] . '</td>';
								echo '<td>';
									echo '<form action="function/admin_function.php" method="POST">';
									echo '<input type="hidden" id="doctorID" name="doctorID" value="' . $doctor['user_id'] . '"/>';
									echo '<input type="hidden" id="from" name="from" value="admin.php#doctor"/>';
									if ($doctor['doctor_verified'] === 1) {
										echo '<input type="submit" name="unverifyDoctor" value="Unverify" class="btn btn-primary"/> ';
									} else {
										echo '<input type="submit" name="verifyDoctor" value="Verify" class="btn btn-primary"/> ';
									}
									echo' </form>';
								echo '</td>';
								echo '</tr>';
							}
						}
					?>
					</table>					
					
					<form action="function/admin_function.php" method="POST">
					<label for="name"> Name: </label> 
					<input type="text" id="name" name="name" /> <br />
					<label for="address"> Address: </label> 
					<input type="text" id="address" name="address" /> <br />
					<label for="contact"> Contact: </label> 
					<input type="text" id="contact" name="contact" /> <br />
					<input type="hidden" id="from" name="from" value="admin.php"/>
					<input type="submit" name="enterHospital" value="Add Hospital" /> <br /> 
					</form>			
					
					<hr />
					
    </div>
    </div>
    </div> <!-- /container -->